<template>
  <div class="home-new" ref="target">
    <HomePanel title="人气推荐" subTitle="人气爆款 不容错过">
      <transition name="fade">
      <!-- 默认插槽 -->
      <ul ref="pannel" class="goods-list" v-if="goods.length">
      <li v-for="item in goods" :key="item.id">
        <RouterLink to="/">
          <img v-src="item.picture" alt="">
          <p class="name">{{item.title}}</p>
          <p class="desc">{{item.alt}}</p>
        </RouterLink>
      </li>
    </ul>
    <!-- 骨架屏 -->
    <HomeSkeleton v-else/>
    </transition>
    </HomePanel>
  </div>
</template>
<script>
import HomePanel from './home-panel.vue'
import { findHot } from '@/api/home'
import HomeSkeleton from './home-skeleton.vue'
import { useLazyData } from '@/hooks/index'
export default {
  components: { HomePanel, HomeSkeleton },
  name: 'HomeHot',
  setup () {
    // 调用钩子函数的懒加载获取商品数据
    const { result: goods, target } = useLazyData(findHot)
    return { goods, target }
  }
}
</script>
<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
